package com.briup.estore.Service;

import com.briup.estore.bean.Category;
import com.briup.estore.mapper.CategoryMapper;
import com.briup.estore.utils.BeanCopyUtils;
import com.briup.estore.utils.TreeDataUtils;
import com.briup.estore.vo.CategoryInfoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service

public class CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    public List<CategoryInfoVO> findAll() {
        //原始数据
        List<Category> categorys = categoryMapper.findAll();
        //将category   ->转换成前端需要的树形结构数据
        List<CategoryInfoVO> categoryInfoVOS = BeanCopyUtils.copyBeanList(categorys,CategoryInfoVO.class);
        //重新赋值  接收  嵌套的三条数据
        categoryInfoVOS = TreeDataUtils.convert(categoryInfoVOS);
        return categoryInfoVOS;

    }
}
